﻿<?php

// by Max

$nick 	= $_GET['name'];
$count 	= "?count=".$_GET['count'];
if($count == "") {
$count 	= "?count=1";
}
$doc = new DOMDocument();
	$doc->load("http://twitter.com/status/user_timeline/".$nick.".xml".$count);
	$arrFeeds = array();
	foreach ($doc->getElementsByTagName('status') as $node) {
		$itemRSS = array ( 
			'tweeter' 	=> $node->getElementsByTagName('screen_name')->item(0)->nodeValue,
			'text' 		=> $node->getElementsByTagName('text')->item(0)->nodeValue,
			'link' 		=> $node->getElementsByTagName('id')->item(0)->nodeValue,
			'date' 		=> $node->getElementsByTagName('created_at')->item(0)->nodeValue,
			'avatar' 	=> $node->getElementsByTagName('profile_image_url')->item(0)->nodeValue
			);
		array_push($arrFeeds, $itemRSS);
	}
$pattern = '#(^|[^\"=]{1})(http://|ftp://|mailto:|news:|https://)([^\s<>]+)([\s\n<>]|$)#sm';

echo "
<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">
<html lang=\"de\">
<head>
 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">
 <style>
#avatar {
float:left;
}
.tweet {
font:0.75em 'Lucida Grande',sans-serif;
left:10px;
position:relative;
top:2px;
}
.tweet a {
color:#2276BB;
}
.tweeter {
color:#2276BB;
font-size:14px;
text-decoration:none;
}
#ava {
position:absolute;
top:13px;
}
#ava img {
border:1px solid #888888;
height:60px;
width:60px;
}
#tweets {
left:65px;
position:absolute;
}


 </style>
</head>
";

$itemRSS[avatar] = preg_replace("/_normal\./", "_bigger.", $itemRSS[avatar]);
echo "<span id=\"ava\">\r\n<a href=\"http://twitter.com/".$itemRSS[tweeter]."\">\r\n<img id=\"avatar\" src=\"".$itemRSS[avatar]."\">\r\n</a>\r\n</span>\r\n<div id=\"tweets\">";

foreach($arrFeeds as $var) {
$text = preg_replace("/@([a-zA-Z_-][^,;: ]*.)/",  "@<a href=\"http://twitter.com/$1\">$1</a>", $var[text]); 
$text  = preg_replace($pattern,"\\1<a href=\"\\2\\3\">\\2\\3</a>\\4",$text);
$text = preg_replace("/,<\/a>/", '</a>,', $text);
$text = preg_replace("/;<\/a>/", '</a>;', $text);
$text = preg_replace("/:<\/a>/", '</a>:', $text);
$text = preg_replace("/ <\/a>/", '</a> ', $text);
echo "<span class=\"tweet\"><a class=\"tweeter\" href=\"http://twitter.com/".$var[tweeter]."/statuses/".$var[link]."\">".$var[tweeter]."</a>: <span class=\"text\">".$text."</span></span><br>";
}
echo "</div>";
?>